#!/usr/bin/env python

import math
import random
from itertools import *

def mean(lst):
    """Throws a div by zero exception if list is empty"""
    if type(lst) != list:
        lst = list(lst)
    return sum(lst) / float(len(lst))

def stddev(lst):
    if type(lst) != list:
        lst = list(lst)
    if len(lst) == 0:
        return 0
    m = mean(lst)
    return math.sqrt(sum((x-m)*(x-m) for x in lst) / len(lst))
